/**
 * 导航图片列表
 *
 */
define(["app", "comm/pager/PagerControl", "js/services/MessageBox", "js/services/MuseService", "js/directives/FileUpload"], function (app) {

    var deps = ["$scope", "$state", "$modal", "MessageBox", "MuseService"];

    function controller($scope, $state, $modal, MessageBox, MuseService) {
        //初始化查询对象 和 分页对象
        $scope.queryObj = $scope.queryObj || {};
        $scope.pagerObj = $scope.pagerObj || {};

        //获取列表
        $scope.getObjList = function (pageNo, pageSize) {
            var curPage = pageNo ||$scope.pagerObj.currentPage ||1;
            var param = {
                page: curPage,
                param: {
                    type: $scope.queryObj.type || "",
                    state: $scope.queryObj.state || ""
                }
            };

            MuseService.postObj(baseServices_restfulUrl + "sysGuidePic/search.json", param).success(
                function (data, status, headers, config) {
                    // console.log(data);
                    if (data.state == 0) {
                        var page = data.data;
                        $scope.sysGuidePicList = page.data;
                        //分页器
                        $scope.pagerObj = PageCtrl().page($scope.pagerObj, page.total, curPage);
                    }
                })
                .error(function () {
                    MessageBox.error('服务器正在开小差zZZ,获取不到数据');
                });
        };

        $scope.getObjList();

        //新增
        $scope.add = function () {
            $state.go('sysGuidePicEdit');
        };

        //删除
        $scope.delete = function (sysGuidePic) {
            var dialog = MessageBox.confirm('确认要删除该信息吗？');
            dialog.result.then(function () {
                MuseService.post(baseServices_restfulUrl + 'sysGuidePic/delete.json', {id: sysGuidePic.id}).success(
                    function (data) {
                        if (data.state == 0) {
                            MessageBox.notify({msg: '删除成功！', displayTime: 1000});
                            $scope.getObjList();
                        } else {
                            MessageBox.error('删除异常：' + data.message || "服务器正在开小差");
                        }
                    })
                    .error(function () {
                        MessageBox.error('删除失败：服务器正在开小差');
                    });
            });
        };

        //编辑
        $scope.edit = function (id) {
            $state.go('sysGuidePicEdit', {id: id});
        };

        $scope.pageChanged = function () {
            PageCtrl().check($scope.pagerObj);
            $scope.getObjList($scope.pagerObj.currentPage);
        }
    }

    controller.$inject = deps;
    app.lazy.controller("SysGuidePicListController", controller);
});
